package com.inspection.controller;

import com.inspection.entity.InspectionBasicDO;
import com.inspection.model.dto.InspectionBasicDTO;
import com.inspection.model.dto.InspectionBasicQueryDTO;
import com.inspection.model.vo.InspectionTypeVO;
import com.inspection.service.InspectionBasicService;
import com.inspection.support.Wrapper;
import com.inspection.support.anno.SysLogAnno;
import com.inspection.support.model.ItemList;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author : chenjx
 * create at:  2020/11/8  6:59 下午
 */
@RestController
public class InspectionBasicController {

    @Autowired
    private InspectionBasicService inspectionBasicService;


    @ApiOperation("获取可选的考核类型")
    @RequestMapping("/inspect/basic/type/query")
    public Wrapper<InspectionTypeVO> queryInspectionType(){
        return  Wrapper.ok(InspectionTypeVO.builder().items(inspectionBasicService.queryUsableRegulationType()).build());
    }



//    @CrossOrigin
//    @ApiOperation("获取考核基础列表")
//    @RequestMapping("/inspect/basic/query")
//    public Wrapper<ItemList<InspectionBasicDO>> getInspectionBasicList(@RequestBody InspectionBasicQueryDTO query){
//
//        return Wrapper.ok(ItemList.buildItems(inspectionBasicService.getInspectionBasicList(query)));
//    }


    @ApiOperation("获取考核基础分页")
    @RequestMapping("/inspect/basic/page")
    public Wrapper<Page<InspectionBasicDO>> pageInspectionBasicList(@RequestBody InspectionBasicQueryDTO query){

        return Wrapper.ok(inspectionBasicService.pageInspectionBasic(query));
    }

    @SysLogAnno(operateCode =110101,operateName = "考核基础：新增")
    @RequestMapping("/inspect/basic/save")
    public Wrapper<String> addInspectionBasic(@RequestBody  InspectionBasicDO basicDO){
        basicDO.setDateCreate(new Date());
        inspectionBasicService.addInspectionBasic(basicDO);
        return Wrapper.ok("ok");
    }


    @RequestMapping("/inspect/basic/get")
    public Wrapper<InspectionBasicDO> getInspectionBasic(@RequestBody InspectionBasicQueryDTO query) {
        return Wrapper.ok(inspectionBasicService.getInspectionBasic(query));
    }

    @SysLogAnno(operateCode =110102,operateName = "考核基础：编辑")
    @RequestMapping("/inspect/basic/update")
    public Wrapper<String> updateInspectionBasic(@RequestBody  InspectionBasicDO basic){
        inspectionBasicService.updateInspectionBasic(basic);
        return Wrapper.ok("ok");
    }
    @SysLogAnno(operateCode =110103,operateName = "考核基础：删除")
    @RequestMapping("/inspect/basic/del")
    public Wrapper<String> delInspectionBasic(@RequestBody  InspectionBasicDO basic){
        inspectionBasicService.delInspectionBasic(basic);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =110104,operateName = "考核基础：批量删除")
    @RequestMapping("/inspect/basic/batchDel")
    public Wrapper<String> batchDelInspectionBasic(@RequestBody InspectionBasicDTO del){
        inspectionBasicService.batchDelInspectionBasic(del);
        return Wrapper.ok("ok");
    }


}
